// index.js
const app = getApp()
Page({
  data: {
    // 导航栏 高度
    navHeight: app.globalData.navHeight,
    logoBgColor: 'transparent',
    logoOpacity: 0,
    scrollTop: 0,

    // 轮播图测试数据
    swiperData: [
      { id: 1, title: '这是标题01', img: '/static/banner.png', pathurl: '#' },
      { id: 2, title: '这是标题02', img: '/static/banner.png', pathurl: '#' },
    ],

    // iconList
    iconList: [
      { id: 1, name: '卫浴电器', src: '/static/pro_icon01.png', url: '/pages/product/list?classid=1' },
      { id: 2, name: '厨房电器', src: '/static/pro_icon02.png', url: '/pages/product/list?classid=2' },
      { id: 3, name: '阳台电器', src: '/static/pro_icon03.png', url: '/pages/product/list?classid=3' },
      { id: 4, name: '灯光照明', src: '/static/pro_icon04.png', url: '/pages/product/list?classid=4' },
      { id: 5, name: '环境电器', src: '/static/pro_icon05.png', url: '/pages/product/list?classid=5' },
      { id: 6, name: '集成吊顶', src: '/static/pro_icon06.png', url: '/pages/product/list?classid=6' },
      { id: 7, name: '全屋背景墙', src: '/static/pro_icon07.png', url: '/pages/product/list?classid=7' },
      { id: 8, name: '全功能阳台', src: '/static/pro_icon08.png', url: '/pages/product/list?classid=8' },
    ],

    // TAB
    curTab: 0,
    tabList: [
      { id: 1, name: '卫浴电器' },
      { id: 2, name: '厨房电器' },
      { id: 3, name: '阳台电器' },
      { id: 4, name: '灯光照明' },
      { id: 5, name: '环境电器' },
      { id: 6, name: '集成吊顶' },
      { id: 7, name: '全屋背景墙' },
      { id: 8, name: '全功能阳台' }
    ],


  },
  /**
   * 生命周期函数--监听页面加载
   */
    onLoad(options) {
      // app._startInit(options).then((data) => {
      //     //获取轮播图
      //     this.getbanner()
      //     this._loadHomeSwiper();
      //     //获取商品
          
      //       this.getCarList()
      //       if (options.topage) {
      //           let tmp_topage = options.topage;
      //           app.topageDone(tmp_topage, options);
      //           //return '';
      //       }
            
      //   });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  /*
   * 通用跳转
   */
  m_appurl: function (e) {
    let url = e.currentTarget.dataset.url;
    let type = '';
    if (e.currentTarget.dataset.type) {
      type = e.currentTarget.dataset.type;
    }
    app.m_tourl(url, type);
  },

  // TAB切换
  changeTab: function(e) {
    let curIndex = e.currentTarget.dataset.index
    this.setData({
      curTab: curIndex
    });

    
  },

  // 页面滚动，改变顶部logo背景
  onPageScroll: function (e) {
    let scrollTop = e.scrollTop;
    // 最大透明度为1，滚动距离超过400px后不再增加透明度
    let opacity = Math.min(1, scrollTop / 400);
    if (scrollTop === 0) {
        this.setData({
            logoBgColor: 'transparent',
            logoOpacity: 0
        });
    } else {
        this.setData({
            logoBgColor: `rgba(255, 255, 255, ${opacity})`,
            logoOpacity: opacity
        });
    }
    this.setData({
        scrollTop: scrollTop
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

    },
    _loadHomeSwiper() {
        //let access_token = wx.getStorageSync(ACCESS_TOKEN);
        app.get("c=home&a=common", {
            //access_token: access_token,
            pid: 5,
          })
          .then((data) => {
            console.log(data);
              if (data.length > 0) {
                  let isshow = true;
                let qa = data.map((item) => {
                    let obj = {}
                        obj.id = item.did
                        obj.show = isshow
                        obj.title = item.title
                        obj.desc = item.extenddata.descshow
                        isshow = false
                        return obj
                   
                })
                this.setData({
                    qaList:qa
                })
            }
          });
    },
    msgadd() {
        if (this.data.tel_mail == null || this.data.tel_mail =='') {
            app.m_showhint("请填写联系方式")
            return;
        }
        app.post("c=msg&a=addmsg", {
            type: 1,
            contact: this.data.tel_mail,
            contactuname: '',
            cartype: '',
            rid: '',
            descinfo:''
            
        }).then((data) => { 
            app.m_showhint("提交成功，我们的工作人员会尽快与您联系，请注意接听。")
            this.setData({
                tel_mail:''
            })
        }
    )
    },
    getCarList() {
        app.get("c=car&a=getindexreport", {}).then((data) => {
            this.setData({
                carlist:data
            })
        })
    },
    getbanner() {
        //let access_token = wx.getStorageSync(ACCESS_TOKEN);
        app.get("c=home&a=common", {
            //access_token: access_token,
            pid: 119,
          })
          .then((data) => {
            console.log(data);
              if (data.length > 0) {
               
                this.setData({
                    bannerimg:data[0]['extenddata']['imgs']
                })
            }
          });
    },
})

